/**
 * 
 */
package net.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.miao.framework.dao.BaseDao;
import cn.miao.framework.factory.DaoFactory;
import net.service.PrintPhotoService;

/**
 * @author yangshengfei
 * @createTime 2015年12月17日
 * @updateTime 2015年12月17日
 * @描述:
 */
public class PrintPhotoServiceImpl implements PrintPhotoService {
	
	BaseDao dao=DaoFactory.getDao("MyPrintPhoto");

	/**
	 * 
	 */
	public PrintPhotoServiceImpl() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#userLogin(java.lang.String, java.lang.String)
	 */
	@Override
	public Map<String, Object> userLogin(String userName, String password) {
		// TODO Auto-generated method stub
		Map<String, Object> rMap=new HashMap<String, Object>();
		
		String sqlString="select * from user_tab where User_Name=? and User_Password=?";
		rMap=dao.executeQueryObject(sqlString, new Object[]{userName,password});
		
 		return rMap;
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#createContact(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@SuppressWarnings({ "finally" })
	@Override
	public Map<String, Object> createContact(String userName,
			String contactName, String contactPhone, String contactAddress) {
		// TODO Auto-generated method stub
		Map<String, Object> rMap=new HashMap<String, Object>();
		
		try {
			String sqlString="insert into contacts_tab values(?,?,?,?)";
			dao.executeSQL(sqlString, new Object[]{userName,contactName,contactPhone,contactAddress});
			
			rMap.put("code", 1);
			rMap.put("msg", "新增收货人信息成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			rMap.put("code", 2);
			rMap.put("msg", "新增收货人信息失败");
			//e.printStackTrace();
		}finally{
			return rMap;
		}
 		
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#updateContact(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@SuppressWarnings({ "finally" })
	@Override
	public Map<String, Object> updateContact(String userName,
			String contactName, String contactPhone, String contactAddress) {
		// TODO Auto-generated method stub
		Map<String, Object> rMap=new HashMap<String, Object>();
		
		try {
			String sqlString="update contacts_tab set Contact_Phone=?,Contact_Address=? where User_Name=? and Contact_Name=?";
			dao.executeSQL(sqlString,
					new Object[]{contactPhone,contactAddress,userName,contactName});
			
			rMap.put("code", 1);
			rMap.put("msg", "更新收货人信息成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			rMap.put("code", 2);
			rMap.put("msg", "更新收货人信息失败");
			//e.printStackTrace();
		}finally{
			return rMap;
		}
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#deleteContact(java.lang.String)
	 */
	@SuppressWarnings({ "finally" })
	@Override
	public Map<String, Object> deleteContact(String userName) {
		// TODO Auto-generated method stub
		Map<String, Object> rMap=new HashMap<String, Object>();
		
		try {
			String sqlString="delete from contacts_tab where User_Name=?";
			dao.executeSQL(sqlString, new Object[]{userName});
			
			rMap.put("code", 1);
			rMap.put("msg", "删除收货人信息成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			rMap.put("code", 2);
			rMap.put("msg", "删除收货人信息失败");
			//e.printStackTrace();
		}finally{
			return rMap;
		}
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#getContacts(java.lang.String)
	 */
	@Override
	public List<Map<String, Object>> getContacts(String userName) {
		// TODO Auto-generated method stub
		String sqlString="select * from contacts_tab where User_Name=?";
		return dao.executeQuery(sqlString, new Object[]{userName});
		
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#submitOrderMenu(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@SuppressWarnings("finally")
	@Override
	public Map<String, Object> submitOrderMenu(String order_ID,String product_des,
			String product_price, String product_delivery,
			String product_count, String product_total, String leaveMsg,
			String contact_name, String contact_phone, String contact_address,
			String user_name, String pay,String photo_name) {
		// TODO Auto-generated method stub
		Map<String, Object> rMap=new HashMap<String, Object>();
		
		try {
			String sqlString="insert into order_tab (orderID,product_des,product_price,product_delivery,product_count"
							+",product_total,leaveMsg,contact_name,contact_phone,contact_address,user_name,pay,photo_name) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
			dao.executeSQL(sqlString, new Object[]{order_ID,product_des,product_price,product_delivery,product_count,
					 product_total,leaveMsg,contact_name,contact_phone,contact_address,user_name,pay,photo_name});
			rMap.put("code", 1);
			rMap.put("msg", "提交订单信息成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			rMap.put("code", 2);
			rMap.put("msg", "提交订单信息失败");
			//e.printStackTrace();
		}finally{
			return rMap;
		}
		
	}

	/* (non-Javadoc)
	 * @see net.htwater.service.PrintPhotoService#getOrderMenus(java.lang.String)
	 */
	@Override
	public List<Map<String, Object>> getOrderMenus(String userName) {
		// TODO Auto-generated method stub
		String sqlString="select * from order_tab where user_name=?";
		return dao.executeQuery(sqlString, new Object[]{userName});
	}

}
